$(document).ready(function () {
    $('body').height($('body')[0].clientHeight);
});
// 检查登录
checkLogin();
var work_info = getCache(login_key);
var mid = GetQueryString("mid");
var data = {mid: mid, wid: work_info.wid, sid: work_info.sid, aid: work_info.aid};
var dataArr =[];
var title = '';
var num = '';
var num1 = '';
var showcontent = '';
$("#waterbill_id_value").change(function () {
    if (dataArr.length > 0) {
        for (var i = 0; i < dataArr.length; i++) {
            if (dataArr[i]['goods_name'] == $("#waterbill_id_value").val()) {
                title = dataArr[i]['goods_name'];
                $("#goods_id").val(dataArr[i]['id']);
            }
        }
    }
});

var success = function(res){
    var charge_list = res.data;
    var html = template('bill_data',charge_list);
    document.getElementById('content-block').innerHTML = html;
    dataArr = charge_list.goodsList;
    var values = [];
    for (var i = 0; i < dataArr.length; i++) {
        values[i] = dataArr[i].goods_name;
    }
    $('.picker').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left  close-picker" style="color:#0a8ddf;" >取消</button>\
          <button class="button button-link pull-right close-picker" style="color:#0a8ddf;">确定</button>\
          </header>',
        cols: [
            {
                textAlign: 'center',
                values: values
            }
        ]
    });

};
getData(worker_create_order,data,success);


// 验证表单并处理登录交互

function numValue() {
    num = $('#nums').val();
    num1 = $('#nums1').val();
    if(title && num && num1 ){
        showcontent = '<p>'+'商品名称：' +title+'</p>'+'<p>'+'商品数量：' +num+'</p>'+'<p>'+'订单金额：' +num1+'</p>';
    }
    return '<p>'+showcontent+'</p>';
}
var ajaxOption = {
    url: worker_create_order,
    method: 'POST',
    confirm:true,
    confirm_title:'数据确认',
    confirm_content:['numValue'],//用[]包起来表示该值是函数，不包则为字符串
    data:{mid: mid, wid: work_info.wid, sid: work_info.sid, aid: work_info.aid,type:1},
    success: function (res) {
        setTimeout(function () {
            redirect('import.html');
        },2000)
    }
};
checkform($('#form1'), ajaxOption);